package com.kwm.Controller;
import com.kwm.Service.impl.DeptServiceimpl;
import com.kwm.entity.Dept;
import com.kwm.entity.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Scope;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Lazy // 延迟加载，加上注解后，重新启动项目时，bean 对象不会再初始化，运行会快。

@Scope("Singleton")  // 单例作用域，就是都是同一个bean对象
//@Scope("Prototype") //非单例 作用域， 每创建一次，bean对象不同。
@RequestMapping("/depts")
@RestController
public class DeptController {
    @Autowired
    private DeptServiceimpl depts;
//    @RequestMapping(value = "/depts",method = RequestMethod.GET)
    @GetMapping
    public Result getAll(){
        List<Dept> list = depts.list();
        return Result.success(list);
    }


    @DeleteMapping
    public Result delete(Integer id){

        depts.delete(id);

        return Result.success();

    }
    @PostMapping
    public Result add(@RequestBody Dept dept){
        depts.add(dept);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        Dept dept = depts.getById(id);
        return Result.success(dept);
    }
    @PutMapping
    public Result update(@RequestBody Dept dept){
        depts.update(dept);
        return Result.success();
    }


}
